package com.order.service;

import com.order.mapper.OrderMapper;
import com.order.pojo.Order;
import com.order.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Service
public class OrderService {

    //@Autowired
    @Resource
    private OrderMapper orderMapper;

    @Resource
    private RestTemplate restTemplate;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
//        Order order = orderMapper.findById(orderId);
        // TODO 2.查询用户

        // 3.封装user信息
//        order.setUser(null);
        // 4.返回
//        return order;

        //查询订单
        Order order=orderMapper.findById(orderId);
        //远程查询user
        //url地址
//        String url="http://127.0.0.1:8081/user/"+order.getUserId();
        String url="http://userService/user/"+order.getUserId();
        //发起调用
        User user = restTemplate.getForObject(url, User.class);
        //存入order
        order.setUser(user);
        //返回
        return order;
    }
}
